﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.Design.WebControls;
using System.Web.UI.Design;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Web.UI.WebControls;
using System.Windows.Forms;
using EnvDTE;


namespace Catalyst.Web.DynamicData.Design
{
    public class DynamicFilterFormDesigner : DynamicFilterContainerBaseDesigner
    {
        private TemplateGroupCollection _templateGroups;

        public override void Initialize(IComponent component)
        {
            base.Initialize(component);
            SetViewFlags(ViewFlags.TemplateEditing, true);
        }
        
        public DynamicFilterForm FilterControl
        {
            get { return (DynamicFilterForm)Component; }
        }

        public override System.Web.UI.Design.TemplateGroupCollection TemplateGroups
        {
            get
            {
                if (_templateGroups == null)
                {
                    TemplateDefinition td = new TemplateDefinition(this, "FilterTemplate", Component, "FilterTemplate", false);
                    
                    TemplateGroup tg = new TemplateGroup("FilterTemplate");
                    tg.AddTemplateDefinition(td);
                    
                    _templateGroups = new TemplateGroupCollection();
                    _templateGroups.Add(tg);
                }
                return _templateGroups;
            }
        }

        public override string GetDesignTimeHtml()
        {
            if (FilterControl == null || FilterControl.FilterTemplate == null)
                return GetEmptyDesignTimeHtml();

            string html = base.GetDesignTimeHtml();
            
            if (string.IsNullOrEmpty(html))
                return GetEmptyDesignTimeHtml();
            else
                return html;
        }
    }
}
